/**
 * 全局变量
 */
var pageNoOne;//页码
var pageSizeOne;//页码大小
var countOne;//总数
var productTypeName = "";//供应商名称



function ejectProductType(){
	$.jBox($("#divProductType").html(), {
		id: 'jBoxProductType', 
		title : "选择产品类型",
		width : 'auto',
		height : 'auto',
		buttons : {"选择" : false , "关闭" : true },
		submit : function(v, h, f) {
			if (v == false) {
				if(h.find("input[name='radio']:checked").val() != null){
    				$("#productTypeName").attr("value",h.find("input[name='radio']:checked").parent().parent().children("td")[2].innerHTML);
    				$("#productTypeCodeNum").attr("value",h.find("input[name='radio']:checked").parent().parent().children("td")[1].innerHTML);
    				return true;
				}else{
					$.jBox.tip("请选择产品类型！", "warn");
					return false;
				}
			}
		}
	});
}

/**
 * 供应商信息
 */
$("#productTypeName").live('dblclick',function(){
	$("#rowProductType").html("");
	var newRow = '';
	 $.getJSON("/jeesite/a/pro/productRef/productTypeList",function(data){
		 if (typeof(data.list) != "undefined" && data.list.length >= 1){
			$.each(data.list, function(i,info){
				newRow += '<tr><td style="width: 8px;">'
					 +'<input type="radio"class="subBox" name="radio"/></td>';
				if(info.codeNum=="undefined" || info.codeNum==""){
					newRow+= '<td></td>';
				}else{
					newRow+='<td>'+info.codeNum+'</td>';
				}
				if(info.name=="undefined" || info.name==""){
					newRow+= '<td></td>';
				}else{
					newRow+='<td>'+info.name+'</td>';
				}
				if(info.remarks=="undefined" || info.remarks==""){
					newRow+= '<td></td></tr>';
				}else{
					newRow+='<td>'+info.remarks+'</td></tr>';
				}
			});
			$("#rowProductType").append(newRow);
			pageNoOne = data.pageNo;
			pageSizeOne = data.pageSize;
			countOne = data.count;
			$("#productTypePageNo").html(pageNoOne);
			$("#productTypePageSize").html(pageSizeOne);
			$("#productTypeCount").html(countOne);
		 }
		
		if(pageNoOne <= 1){
			$("#productTypePreviousPageLi").attr("class","disabled");
		}
		if(pageNoOne >= countOne/pageSizeOne){
			$("#productTypeNextPageLi").attr("class","disabled");
		}
		//弹出选择框
		ejectProductType();
	});
});

/**
 * 搜索供应商
 * @param obj
 */
function selectProductType(obj){
	productTypeName = $(obj).prev().val();
	$("#rowProductType").html(" ");
	var  newRow = "";
	$.getJSON("/jeesite/a/pro/productRef/productTypeList","name="+productTypeName,function(data){
		if (typeof(data.list) != "undefined" && data.list.length >= 1){
			$.each(data.list, function(i,info){
				newRow += '<tr><td style="width: 8px;">'
					 +'<input type="radio"class="subBox" name="radio"/></td>';
				if(info.codeNum=="undefined" || info.codeNum==""){
					newRow+= '<td></td>';
				}else{
					newRow+='<td>'+info.codeNum+'</td>';
				}
				if(info.name=="undefined" || info.name==""){
					newRow+= '<td></td>';
				}else{
					newRow+='<td>'+info.name+'</td>';
				}
				if(info.remarks=="undefined" || info.remarks==""){
					newRow+= '<td></td></tr>';
				}else{
					newRow+='<td>'+info.remarks+'</td></tr>';
				}
			});
			$("#rowProductType").append(newRow);
			pageNoOne = data.pageNo;
			pageSizeOne = data.pageSize;
			countOne = data.count;
			$("#productTypePageNo").html(pageNoOne);
			$("#productTypePageSize").html(pageSizeOne);
			$("#productTypeCount").html(countOne);
		 }
		if(pageNoOne <= 1){
			$("#productTypePreviousPageLi").attr("class","disabled");
		}
		if(pageNoOne >= countOne/pageSizeOne){
			$("#productTypeNextPageLi").attr("class","disabled");
		}
		$.jBox.close(jBoxProductType);
		ejectProductType();
	});
}

$("#ProductTypeNextPage").live("click",function(){
	if(pageNoOne < countOne/pageSizeOne){
		$("#rowProductType").html("");
		var newRow = "";
		$.getJSON("/jeesite/a/pro/productRef/productTypeList","pageNo="+(pageNoOne+1)+"&name="+productTypeName,function(data){
			if (typeof(data.list) != "undefined" && data.list.length >= 1){
				$.each(data.list, function(i,info){
					newRow += '<tr><td style="width: 8px;">'
						 +'<input type="radio"class="subBox" name="radio"/></td>';
					if(info.codeNum=="undefined" || info.codeNum==""){
						newRow+= '<td></td>';
					}else{
						newRow+='<td>'+info.codeNum+'</td>';
					}
					if(info.name=="undefined" || info.name==""){
						newRow+= '<td></td>';
					}else{
						newRow+='<td>'+info.name+'</td>';
					}
					if(info.remarks=="undefined" || info.remarks==""){
						newRow+= '<td></td></tr>';
					}else{
						newRow+='<td>'+info.remarks+'</td></tr>';
					}
				});
				$("#rowProductType").append(newRow);
				pageNoOne = data.pageNo;
				pageSizeOne = data.pageSize;
				countOne = data.count;
				$("#productTypePageNo").html(pageNoOne);
				$("#productTypePageSize").html(pageSizeOne);
				$("#productTypeCount").html(countOne);
			 }
			if(pageNoOne <= 1){
				$("#productTypePreviousPageLi").attr("class","disabled");
			}
			if(pageNoOne >= countOne/pageSizeOne){
				$("#productTypeNextPageLi").attr("class","disabled");
			}
			$.jBox.close(jBoxProductType);
			ejectProductType();
		});
	}
});

/**
* 客户上一页
*/
$("#productTypePreviousPage").live("click",function(){
	if(pageNoOne > 1){
		$("#rowProductType").html("");
		var newRow = "";
		$.getJSON("/jeesite/a/pro/productRef/productTypeList","pageNo="+(pageNoOne-1)+"&name="+productTypeName,function(data){
			if (typeof(data.list) != "undefined" && data.list.length >= 1){
				$.each(data.list, function(i,info){
					newRow += '<tr><td style="width: 8px;">'
						 +'<input type="radio"class="subBox" name="radio"/></td>';
					if(info.codeNum=="undefined" || info.codeNum==""){
						newRow+= '<td></td>';
					}else{
						newRow+='<td>'+info.codeNum+'</td>';
					}
					if(info.name=="undefined" || info.name==""){
						newRow+= '<td></td>';
					}else{
						newRow+='<td>'+info.name+'</td>';
					}
					if(info.remarks=="undefined" || info.remarks==""){
						newRow+= '<td></td></tr>';
					}else{
						newRow+='<td>'+info.remarks+'</td></tr>';
					}
				});
				$("#rowProductType").append(newRow);
				pageNoOne = data.pageNo;
				pageSizeOne = data.pageSize;
				countOne = data.count;
				$("#productTypePageNo").html(pageNoOne);
				$("#productTypePageSize").html(pageSizeOne);
				$("#productTypeCount").html(countOne);
			 }
			if(pageNoOne <= 1){
				$("#productTypePreviousPageLi").attr("class","disabled");
			}
			if(pageNoOne >= countOne/pageSizeOne){
				$("#productTypeNextPageLi").attr("class","disabled");
			}
			$.jBox.close(jBoxProductType);
			ejectProductType();
		});
	}
});


